package com.example.manage.controller;

import com.example.manage.bean.ClientBannerBean;
import com.example.manage.bean.ResultBean;
import com.example.manage.mapper.ClientBannerMapper;
import com.example.manage.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/clientBanner")
public class ClientBannerController {
    @Autowired
    ClientBannerMapper bannerMapper;

    @RequestMapping("/addBanner")
    @ResponseBody
    public ResultBean addBanner(@RequestBody ClientBannerBean bannerBean) {
        int count = bannerMapper.addBanner(bannerBean);
        return ResultUtil.getResultBean(count, "添加失败");
    }

    @RequestMapping("/updateBanner")
    @ResponseBody
    public ResultBean updateBanner(@RequestBody ClientBannerBean bannerBean) {
        int count = bannerMapper.updateBanner(bannerBean);
        return ResultUtil.getResultBean(count, "修改失败");
    }

    @RequestMapping("/deleteBanner")
    @ResponseBody
    public ResultBean deleteBanner(@RequestBody Map<String, Long> params) {
        int count = bannerMapper.deleteBanner(params.get("id"));
        return ResultUtil.getResultBean(count, "删除失败");
    }

    @RequestMapping("/getBanner")
    @ResponseBody
    public ResultBean getBanner() {
        List<ClientBannerBean> devices = bannerMapper.getBanner();
        return ResultUtil.getSuccessBean(devices);
    }
}
